from scrapy.spider import BaseSpider
from scrapy.selector import Selector

from spider.items import SpiderItem
import MySQLdb
import json

class TestSpider(BaseSpider):

    name = "test"
    conn = MySQLdb.connect(host="localhost",user="spider",passwd="Xjk@4047218?",db="spider")
    cursor = conn.cursor() 
    sql = "select id from sp_ah_carstyle order by id asc limit 1"
    cursor.execute(sql)
    carstyleUrlList = []

    for row in cursor.fetchall():
        carstyleUrlList.append(row[0])
    cursor.close()
    start_urls = ["http://localhost190/a.html"]
   
    def parse(self,response):
        item = SpiderItem()
        sel = Selector(response)
        
        item["page"] = sel.xpath('//div[@id="test"]/text()').extract()
        print type(item)     
        print repr(item)
        #print json.dumps(item)
